package com.jhgsys.internal.incentive.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.incentive.entity.IncentiveGoodsOrderUser;
import com.jhgsys.internal.incentive.service.IIncentiveGoodsOrderUserService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 安全奖励订单人员 Controller
 *
 * @author zhangwei
 * @date 2024-09-02 13:54:57
 */
@Slf4j
@Validated
@Controller
public class IncentiveGoodsOrderUserController extends BaseController {

    @Autowired
    private IIncentiveGoodsOrderUserService incentiveGoodsOrderUserService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveGoodsOrderUser")
    @RequiresPermissions("incentiveGoodsOrderUser:view")
    public String incentiveGoodsOrderUserIndex(){
        return FebsUtil.view("incentive/incentiveGoodsOrderUser/incentiveGoodsOrderUserList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveGoodsOrderUser/add")
    @RequiresPermissions("incentiveGoodsOrderUser:add")
    public String incentiveGoodsOrderUserAdd(){
        return FebsUtil.view("incentive/incentiveGoodsOrderUser/incentiveGoodsOrderUserEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "incentiveGoodsOrderUser/update/{id}")
    @RequiresPermissions("incentiveGoodsOrderUser:edit")
    public String incentiveGoodsOrderUserUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("incentiveGoodsOrderUser", incentiveGoodsOrderUserService.findIncentiveGoodsOrderUserById(id));
        return FebsUtil.view("incentive/incentiveGoodsOrderUser/incentiveGoodsOrderUserEdit");
    }

    /**
     * 查询（所有）
     * @author zhangwei
     * @date 2024-09-02 13:54:57
     */
    @GetMapping("incentiveGoodsOrderUser")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderUser:view")
    public FebsResponse getAllIncentiveGoodsOrderUsers(IncentiveGoodsOrderUser incentiveGoodsOrderUser) {
        return new FebsResponse().success().data(incentiveGoodsOrderUserService.findIncentiveGoodsOrderUserList(incentiveGoodsOrderUser));
    }

    /**
     * 查询（分页）
     * @author zhangwei
     * @date 2024-09-02 13:54:57
     */
    @GetMapping("incentiveGoodsOrderUser/list")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderUser:view")
    public FebsResponse incentiveGoodsOrderUserList(QueryRequest request, IncentiveGoodsOrderUser incentiveGoodsOrderUser) {
        Map<String, Object> dataTable = getDataTable(this.incentiveGoodsOrderUserService.findIncentiveGoodsOrderUserPage(request, incentiveGoodsOrderUser));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 IncentiveGoodsOrderUser
     * @author zhangwei
     * @date 2024-09-02 13:54:57
     */
    @Log("新增IncentiveGoodsOrderUser")
    @PostMapping("incentiveGoodsOrderUser")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderUser:add")
    public FebsResponse addIncentiveGoodsOrderUser(@Valid IncentiveGoodsOrderUser incentiveGoodsOrderUser) throws FebsException {
        try {
            incentiveGoodsOrderUser.setCreatedBy(getCurrentUser().getUserName());
            this.incentiveGoodsOrderUserService.createIncentiveGoodsOrderUser(incentiveGoodsOrderUser);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增IncentiveGoodsOrderUser失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 逻辑删除 IncentiveGoodsOrderUser
     * @author zhangwei
     * @date 2024-09-02 13:54:57
     */
    @Log("逻辑删除IncentiveGoodsOrderUser")
    @GetMapping("incentiveGoodsOrderUser/delete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderUser:delete")
    public FebsResponse deleteIncentiveGoodsOrderUser(@PathVariable("id") String incentiveGoodsOrderUserIds) throws FebsException {
        try {
            IncentiveGoodsOrderUser incentiveGoodsOrderUser = new IncentiveGoodsOrderUser();
            incentiveGoodsOrderUser.setDeletedBy(getCurrentUser().getUserName());
            incentiveGoodsOrderUser.setDeletedTime(new Date());
            incentiveGoodsOrderUser.setDeletedFlg(FebsConstant.INVALID);
            this.incentiveGoodsOrderUserService.deleteIncentiveGoodsOrderUser(incentiveGoodsOrderUser,incentiveGoodsOrderUserIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveGoodsOrderUser失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
    * 物理删除 IncentiveGoodsOrderUser
    * @author zhangwei
    * @date 2024-09-02 13:54:57
    */
    @Log("物理删除IncentiveGoodsOrderUser")
    @GetMapping("incentiveGoodsOrderUser/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderUser:delete")
    public FebsResponse physicallyDeleteIncentiveGoodsOrderUser(@PathVariable("id") String incentiveGoodsOrderUserIds) throws FebsException {
        try {
            this.incentiveGoodsOrderUserService.physicallyDeleteIncentiveGoodsOrderUser(incentiveGoodsOrderUserIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除IncentiveGoodsOrderUser失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    /**
     * 修改 IncentiveGoodsOrderUser
     * @author zhangwei
     * @date 2024-09-02 13:54:57
     */
    @Log("修改IncentiveGoodsOrderUser")
    @PostMapping("incentiveGoodsOrderUser/update")
    @ResponseBody
    @RequiresPermissions("incentiveGoodsOrderUser:edit")
    public FebsResponse updateIncentiveGoodsOrderUser(IncentiveGoodsOrderUser incentiveGoodsOrderUser) throws FebsException {
        try {
            incentiveGoodsOrderUser.setUpdatedBy(getCurrentUser().getUserName());
            this.incentiveGoodsOrderUserService.updateIncentiveGoodsOrderUser(incentiveGoodsOrderUser);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改IncentiveGoodsOrderUser失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

}
